﻿@{
    Layout = null;
}
@using CNKI.TPI.Web.Admin.Model;
@using CNKI.TPI.Web.Search.Model;
<script>
    var myTree;
    function selectCate() {
        cateShow();
        clsChange();
    }
    function cateShow() {
        $(".talkDivBg").show();
        $(".pageform").show();
    }
    function catehide() {
        $(".talkDivBg").hide();
        $(".pageform").hide();
    }
    function sureCate() {
        if (typeof (myTree) != "undefined") {
            checkstr = myTree.getSelectedItemId();
            if (checkstr != "") {
                $("#cateCode").val(checkstr);
                $("#cateName").html($("#subjectCate option:selected").text() + "--" + myTree.getSelectedItemText());
                catehide();
                bindDB(checkstr);

            }
            else {
                messageAlert("请选择分类！");
            }
        }
        else {
            messageAlert("请选择分类！");
        }

    }
    function bindDB(nodecode) {
        //绑定数据库
        $.ajax({
            type: "GET",
            url: timestamp("@Html.Raw(Url.Action("GetDBCls", "Admin_Topic"))"),
            data: { "nodecode": nodecode, "clscode": $("#subjectCate").val() },
            success: function (msg) {
                ;
                $("#dbInfo").empty();
                if (msg != null && msg != "") {
                    $.each(msg, function (index, entry) {//ajax回调后,循环.
                        var option = "<option value=" + entry['DBCode'] + " >" + entry['DBName'] + "</option>";
                        $("#dbInfo").append(option);
                    });

                    $("#dbInfo").val($("#dbselect").val());//修改时赋值
                }
            }
        })

    }
    function clsChange() {
        var clscode = $("#subjectCate").val();
        treeLoad(clscode);
    }
    function treeLoad(clscode) {
        $.ajax({
            type: "GET",
            url: timestamp("@Html.Raw(Url.Action("GetClsTreeInfo", "Admin_Topic"))"),
            data: { "ClsCode": clscode },
            beforeSend: function () { $("#loadingcode").show(); },
            success: function (msg) {
                if (msg != "") {
                    $("#treeboxbox_tree").empty();
                    myTree = new dhtmlXTreeObject("treeboxbox_tree", "100%", "100%", 0);
                    myTree.setImagePath("../Content/dhtmlxTree/codebase/imgs/dhxtree_skyblue/");
                    myTree.enableThreeStateCheckboxes(false);
                    myTree.enableCheckBoxes(0);
                    myTree.enableSmartXMLParsing(true);
                    myTree.loadXMLString(msg);
                    $("#loadingcode").hide();
                }
                else {
                    $("#loadingcode").hide();
                    $("#treeboxbox_tree").empty();
                    messageAlert("没有获取到分类数据！");
                }
            },
            error: function (e) {
                $("#loadingcode").hide();
                $("#treeboxbox_tree").empty();
                messageAlert("系统异常，请稍后重试");
            }
        })
    }
    function disablesave() {
        $(".btn-warn-f").attr("disabled", "disabled");
    }
    function enablesave() {
        $(".btn-warn-f").removeAttr("disabled", "disabled");
    }
    function savedata() {
        disablesave();
        if ($.trim($("#columnName").val()) == "") {
            messageAlert("请填写栏目名称！");
            enablesave();
            return;
        }
        else {
            if (!regtext($("#columnName").val())) {
                messageAlert("请输入栏目名称(不允许输入特殊字符)！");
                enablesave();
                return;
            }
        }
        if ($("#cateCode").val() == "") {
            messageAlert("请选择导航！");
            enablesave();
            return;
        }
        ;
        if ($("#dbInfo").val() == "" || $("#dbInfo").val() == null) {
            messageAlert("请选择数据库！");
            enablesave();
            return;
        }
        //if ($("input[name='setnum']").val() == "" || !regnum($("input[name='setnum']").val())) {
        //    messageAlert("请填写记录显示条数(正整数)！");
        //    enablesave();
        //    return;
        //}
        //if ($("input[name='setlength']").val() == "" || !regnum($("input[name='setlength']").val())) {
        //    messageAlert("请填记录显示长度(正整数)！");
        //    enablesave();
        //    return;
        //}

        if ($("#obsertype").val() == "") {
            messageAlert("请选择显示类型！");
            enablesave();
            return;
        }


        var insertdata = {
            "DBName": $("#dbInfo option:selected").text(), "DBCode": $("#dbInfo").val(), "ShowType": $("#obsertype").val(),
            "TopicCode": $("#TopicCode").val(), "NodeCode": $("#cateCode").val(), "IsPub": $("input[name='display']:checked").val(),
            "ArticleNum": $("#setnum").val(), "ArticleLength": $("#setlength").val(), "SYSID": $("#sysid").val(), "CLSCode": $("#subjectCate").val(),
            "ColumnName": $("#columnName").val(), "Location": $("input[name='position']:checked").val(), "STATUS": 1, "SORTNO": $("#sort").val()
        };
        var saveurl = "@Html.Raw(Url.Action("SavePageConfig", "Admin_Topic"))";
        var savedata = { "obj": insertdata };
        $.ajax({
            type: "POST",
            url: saveurl,
            data: JSON.stringify(savedata),
            contentType: "application/json",
            success: function (m) {
                if (m == "True") {
                    messageAlert("操作成功！");
                    backlist();
                }
                else {
                    messageAlert("操作失败！");
                }
            },
            error: function (e)
            { }
        })
    }
    function backlist() {
        ajaxLoad('initload', "@Html.Raw(Url.Action("SubjectSetList", "Admin_Topic"))?TopicName=" + escape($("#TopicName").val()) + "&TopicCode=" + $("#TopicCode").val());
    }
    $(function () {
        //页面加载
        var sysid = $("#sysid").val();
        if (sysid != 0) //编辑
        {
            $("#obsertype").val($("#obser").val());
            //bindDB($("#cateCode").val());
            $('#dbInfo').val($("#DBCode").val());

        }
    })
</script>
<style>
    .containerTableStyle {
        overflow: auto !important;
    }
</style>
<div class="wrapR-c" style='padding-top: 20px;'>
    <input type="hidden" id="TopicCode" name="TopicCode" value="@ViewBag.TopicCode" />
    <input type="hidden" id="TopicName" name="TopicName" value="@ViewBag.TopicName" />
    <input type="hidden" id="TopicDB" name="TopicDB" value="@ViewBag.TopicDB" />
    <input type="hidden" id="DBCode" name="DBCode" value="@ViewBag.DBCode" />
    <input type="hidden" id="sysid" name="sysid" value="@ViewBag.SysID" />




    @{ SYS_CMS_TOPIC_PAGECONFIG obj = new SYS_CMS_TOPIC_PAGECONFIG();
       if (ViewBag.PageInfo != null)
       {
           obj = ViewBag.PageInfo;
       }
        <input type="hidden" id="sort" name="sort" value="@obj.SORTNO" />
        <input type="hidden" id="obser" name="obser" value="@obj.ShowType" />
        <input type="hidden" id="dbselect" name="dbselect" value="@obj.DBCode" />
        
        
        <div class="box">

            @if (ViewBag.SysID == "0")
            {
                <h3 class='box-h'>专题库首页管理—栏目配置—新建栏目
                </h3> 
            }
            else
            {  <h3 class='box-h'>专题库首页管理—栏目配置—编辑栏目
            </h3>
            }

            <form id="saveform">
                <fieldset>
                    <div class="box-b box-b-m form-h form-h-8em form-wr f14">
                        <div class="f-gp">
                            <div class="f-lb">
                                <label class="f-label">栏目名称：</label>
                            </div>
                            <div class="f-ct">
                                <input class="f-text span3" id="columnName" value="@obj.ColumnName" maxlength="20" />
                                <span class="f-label-re">* </span>
                            </div>
                        </div>
                        @*<div class="f-gp">
                            <div class="f-lb">
                                <label class="f-label">选择分类导航：</label>
                            </div>
                            <div class="f-ct">
                                <input type="button" class="btn btn-m btn-submit btn-defa-f" onclick="selectCate()" value="选择" />
                                <label id="cateName">@ViewBag.CLsNodeName</label>
                                <input type="hidden" id="cateCode" value="@obj.NodeCode" />
                                <span class="f-label-re">* </span>
                            </div>
                        </div>*@
                        <div class="f-gp">
                            <div class="f-lb">
                                <label class="f-label">来源数据库：</label>
                            </div>
                            <div class="f-ct">
                                <select id="dbInfo" class="f-select span3">
                                    @{
                                        if (ViewBag.DBList != null)
                                        {
                                            foreach (SYS_CMS_TOPIC_DBCONFIG item in ViewBag.DBList)
                                            {
                                                <option value="@item.DBCode">@item.DBName</option>
                                            }

                                        }
                                    }
                                </select>
                                <span class="f-label-re">* </span>
                            </div>
                        </div>

                        <div class="f-gp disnone">
                            <div class="f-lb">
                                <label class="f-label">记录显示条数：</label>
                            </div>
                            <div class="f-ct">
                                <input type="text" onkeyup="value=value.replace(/[^\d.]/g,'')" class="f-text span3" id="setnum" name="setnum" maxlength="8" value="@obj.ArticleNum">
                                <span class="f-label-re">*</span>
                            </div>
                        </div>

                        <div class="f-gp disnone">
                            <div class="f-lb">
                                <label class="f-label">记录显示长度：</label>
                            </div>
                            <div class="f-ct">
                                <input type="text" onkeyup="value=value.replace(/[^\d.]/g,'')" class="f-text span3" id="setlength" name="setlength"  maxlength="8" value="@obj.ArticleLength">
                                <span class="f-label-re">*</span>
                            </div>
                        </div>


                        <div class="f-gp">
                            <div class="f-lb">
                                <label class="f-label">是否显示：</label>
                            </div>
                            <div class="f-ct">
                                @{
                               
                                    if (@obj.IsPub == 0)
                                    {
                                    <label class="f-label">
                                        <input type="radio" class="f-radio" name='display' value="0" checked="checked">
                                        显示</label>
                                    <label class="f-label">
                                        <input type="radio" class="f-radio" name='display' value="1">
                                        不显示</label>
                                    }
                                    else
                                    {
                                    <label class="f-label">
                                        <input type="radio" class="f-radio" name='display' value="0">
                                        显示</label>
                                    <label class="f-label">
                                        <input type="radio" class="f-radio" name='display' value="1" checked="checked">
                                        不显示</label>
                                    }
                              
                                }
                                <span class="f-label-re">* </span>
                            </div>
                        </div>

                        <div class="f-gp" style="display: none">
                            <div class="f-lb">
                                <label class="f-label">显示位置：</label>
                            </div>
                            <div class="f-ct">
                                @{
                             
                                    if (@obj.Location == 0)
                                    {
                                    <label class="f-label">
                                        <input type="radio" class="f-radio" name='position' value="0" checked="checked">
                                        左侧</label>
                                    <label class="f-label">
                                        <input type="radio" class="f-radio" name='position' value="1">
                                        右侧</label>
                                    }
                                    else
                                    {
                                    <label class="f-label">
                                        <input type="radio" class="f-radio" name='position' value="0">
                                        左侧</label>
                                    <label class="f-label">
                                        <input type="radio" class="f-radio" name='position' value="1" checked="checked">
                                        右侧</label>
                                    }
                                }
                                <span class="f-label-re">* </span>
                            </div>
                        </div>

                        <div class="f-gp disnone">
                            <div class="f-lb">
                                <label class="f-label">显示类型：</label>
                            </div>
                            <div class="f-ct">
                                <select class="f-select span3" id="obsertype" name="obsertype">
                                    <option value="1">文章论文</option>
                                    <option value="2">画作</option>
                                    <option value="3">文学作品</option>
                                    <option value="4">焦点图</option>
                                    <option value="5">简介</option>
                                    <option value="6">影音资料</option>
                                    <option value="7">艺术家风采</option>
                                </select>
                                <span class="f-label-re">* </span>
                            </div>
                        </div>


                    </div>
                </fieldset>
            </form>
            <div class="attention form-h form-h-3em">
                <div class="f-gp">
                    <div class="f-ct" style="padding-left: 200px; padding-bottom: 10px">
                        <button class="btn btn-m btn-submit btn-warn-f" onclick="savedata()">保存</button>
                        <button class="btn btn-m btn-prim-f" onclick="backlist()">返回</button>
                    </div>

                </div>
            </div>



        </div>
    }
</div>


<!--talkDiv弹出层(不带图片，宽550)-->
<!--透明背景-->
<div class="talkDivBg" style="display: none;">
    <div class="talkDiv talkDivTr talkW-550 form-h pageform" style='margin-top: -135px; display: none'>
        <div class="talkDiv-title">
            <span>专题分类</span>
            <a class="icon icon-close" title="关闭" onclick="catehide()" href="javascript:void(0);"><i class="iconfont icon-error3"></i></a>
        </div>
        <div class="talkDiv-body talkDiv-body1">

            <div class="f-gp">
                <div class="f-lb">
                    <label class="f-label">分类导航：</label>
                </div>
                <div class="f-ct">
                    <select id="subjectCate" class="f-select span3" onchange="clsChange()">
                        @foreach (SYS_CMS_TOPIC_CLS item in @ViewBag.ClsList)
                        {
                            if (@item.CLSCode == @ViewBag.CLsNode)
                            {
                            <option value="@item.CLSCode" selected="selected">@item.CLSName</option>
                            }
                            else
                            {
                            <option value="@item.CLSCode">@item.CLSName</option>
                            }
                        }

                    </select>

                </div>
            </div>


            <div class="f-gp" style="margin-top: 15px">
                <div id="loadingcode" style="display: none; position: absolute">
                    <img src="~/Images/loading.gif" width="50" />
                </div>
                <div id="treeboxbox_tree" style="height:250px;">
                </div>

            </div>
        </div>

        <div class="f-gp">
            <div class="f-lb">
                <label class="f-label"></label>
            </div>
            <div class="f-ct" style="margin-left: 150px">
                <a href="javascript:void(0);" class="btn btn-m btn-prim-f btn-submit" onclick="sureCate()">确定</a>
                &#12288;<a href="javascript:void(0);" class="btn btn-m btn-submit btn-defa-f" onclick="catehide()">取消</a>
            </div>
        </div>

    </div>
</div>

<!-- wrapREnd -->
